﻿using CPPEI.Coolzon.UI;
using CPPEI.Coolzon.UI.DataPartLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.Theme.Default.MainViewControl
{
    /// <summary>
    /// MainViewHeader.xaml 的交互逻辑
    /// </summary>
    public partial class Header : UserControl
    {
        private Color backgroundColor;
        public Header()
        {
            InitializeComponent();

            string dayOfWeek = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek);

            tbMessage.Text = DateTime.Now.ToString("yyyy年MM月dd日 ") + dayOfWeek + "   欢迎您-" + UIContext.Current.UserName;
        }

        //[Common.Subscribe]
        //public void OnReceiveNetStateFeedbackEvent(UI.Views.ClientProxyStateFeedbackEvent @event)
        //{
        //    this.Dispatcher.Invoke(() =>
        //    {
        //        double lag = @event.GetAVGLag();
        //        _ctlTextLag.Text = lag.ToString();
        //        if (@event.IsConnected())
        //        {
        //            if (lag <= 300)
        //            {
        //                imgPilotLight.Source = new BitmapImage(new Uri("/CPPEI.Coolzon.ConsoleApp;component/Images/bglv.png", UriKind.Relative));
        //            }
        //            else if (lag > 300 && lag <= 400)
        //            {
        //                imgPilotLight.Source = new BitmapImage(new Uri("/CPPEI.Coolzon.ConsoleApp;component/Images/bghuang.png",UriKind.Relative));
        //            }
        //            else
        //            {
        //                imgPilotLight.Source = new BitmapImage(new Uri("/CPPEI.Coolzon.ConsoleApp;component/Images/bgh.png",UriKind.Relative));
        //            }
        //            if (@event.ProxyStates != null)
        //            {
        //                dataGridProxyState.ItemsSource = @event.ProxyStates;
        //            }
        //        }
        //        else
        //        {
        //            imgPilotLight.Source = new BitmapImage(new Uri("/CPPEI.Coolzon.Theme.Fashion;component/Images/bgh.png", UriKind.Relative));
        //        }
        //    });
        //}

        /// <summary>
        /// 注销事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblLogout_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            LogoutView logoutView = new LogoutView();
            UIContext.Current.RootViewContainer.PopView("注销",logoutView);
        }

        /// <summary>
        /// 点击退出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _ctlTextExit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            CPPEI.Coolzon.Theme.Default.Views.ExitView exitView = new Views.ExitView();
            exitView.Close += exitView_Close;
            UIContext.Current.RootViewContainer.PopView("退出",exitView);
        }

        void exitView_Close(View view, bool isCancel)
        {
            if (!isCancel)
            {
                Application.Current.Shutdown();
            }
        }

        /// <summary>
        /// 点击设置按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _ctlTextSetting_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            CPPEI.Coolzon.Theme.Default.Views.SettingView settingView = new Views.SettingView();
            UIContext.Current.RootViewContainer.PopView("设置", settingView);
        }
    }

    public class BackgroundConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool IsConnected = (bool)value;
            if (IsConnected)
            {
                return new SolidColorBrush(Colors.LightBlue);
            }
            else
            {
                return new SolidColorBrush(Colors.AliceBlue);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
